home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / XML / SVG.php < prev    next >
Encoding:
PHP Script  |  2005-07-07  |  21.5 KB  |  974 lines

  1. <?php
  2. /**
  3.  * XML_SVG
  4.  *
  5.  * Wrapper class that provides some examples and a few convenience
  6.  * methods.
  7.  *
  8.  * $Horde: framework/XML_SVG/SVG.php,v 1.18 2005/01/03 13:09:24 jan Exp $
  9.  *
  10.  * Copyright 2002-2005 Chuck Hagenbuch <chuck@horde.org>
  11.  *
  12.  * See the enclosed file COPYING for license information (LGPL). If you
  13.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  14.  *
  15.  * @package XML_SVG
  16.  */
  17. class XML_SVG {
  18.  
  19.     function example()
  20.     {
  21.         // Create an instance of XML_SVG_Document. All other objects
  22.         // will be added to this instance for printing. Set the height
  23.         // and width of the viewport.
  24.         $svg = &new XML_SVG_Document(array('width' => 400,
  25.                                            'height' => 200));
  26.  
  27.         // Create an instance of XML_SVG_Group. Set the style,
  28.         // transforms for child objects.
  29.         $g = &new XML_SVG_Group(array('style' => 'stroke:black',
  30.                                       'transform' => 'translate(200 100)'));
  31.  
  32.         // Add a parent to the g instance.
  33.         $g->addParent($svg);
  34.  
  35.         // The same results can be accomplished by making g a child of the svg.
  36.         // $svg->addChild($g);
  37.  
  38.         // Create and animate a circle.
  39.         $circle = &new XML_SVG_Circle(array('cx' => 0,
  40.                                            'cy' => 0,
  41.                                            'r' => 100,
  42.                                            'style' => 'stroke-width:3'));
  43.         $circle->addChild(new XML_SVG_Animate(array('attributeName' => 'r',
  44.                                                     'attributeType' => 'XML',
  45.                                                     'from' => 0,
  46.                                                     'to' => 75,
  47.                                                     'dur' => '3s',
  48.                                                     'fill' => 'freeze')));
  49.         $circle->addChild(new XML_SVG_Animate(array('attributeName' => 'fill',
  50.                                                     'attributeType' => 'CSS',
  51.                                                     'from' => 'green',
  52.                                                     'to' => 'red',
  53.                                                     'dur' => '3s',
  54.                                                     'fill' => 'freeze')));
  55.  
  56.         // Make the circle a child of g.
  57.         $g->addChild($circle);
  58.  
  59.         // Create and animate some text.
  60.         $text = &new XML_SVG_Text(array('text' => 'SVG chart!',
  61.                                        'x' => 0,
  62.                                        'y' => 0,
  63.                                        'style' => 'font-size:20;text-anchor:middle;'));
  64.         $text->addChild(new XML_SVG_Animate(array('attributeName' => 'font-size',
  65.                                                   'attributeType' => 'auto',
  66.                                                   'from' => 0,
  67.                                                   'to' => 20,
  68.                                                   'dur' => '3s',
  69.                                                   'fill' => 'freeze')));
  70.  
  71.         // Make the text a child of g.
  72.         $g->addChild($text);
  73.  
  74.         // Send a message to the svg instance to start printing.
  75.         $svg->printElement();
  76.     }
  77.  
  78. }
  79.  
  80. /**
  81.  * XML_SVG_Element
  82.  *
  83.  * This is the base class for the different SVG Element
  84.  * Objects. Extend this class to create a new SVG Element.
  85.  *
  86.  * @package XML_SVG
  87.  */
  88. class XML_SVG_Element {
  89.  
  90.     var $_elements = null;
  91.     var $_style = null;
  92.     var $_transform = null;
  93.     var $_id = null;
  94.  
  95.     function XML_SVG_Element($params = array())
  96.     {
  97.         foreach ($params as $p => $v) {
  98.             $param = '_' . $p;
  99.             $this->$param = $v;
  100.         }
  101.     }
  102.  
  103.     /**
  104.      * Most SVG elements can contain child elements. This method calls
  105.      * the printElement method of any child element added to this
  106.      * object by use of the addChild method.
  107.      */
  108.     function printElement()
  109.     {
  110.         // Loop and call.
  111.         if (is_array($this->_elements)) {
  112.             foreach ($this->_elements as $child) {
  113.                 $child->printElement();
  114.             }
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * This method adds an object reference (or value, if $copy is
  120.      * true) to the _elements array.
  121.      */
  122.     function addChild(&$element, $copy = false)
  123.     {
  124.         if ($copy) {
  125.             $this->_elements[] = &$element->copy();
  126.         } else {
  127.             $this->_elements[] = &$element;
  128.         }
  129.     }
  130.  
  131.     /**
  132.      * This method sends a message to the passed element requesting to
  133.      * be added as a child.
  134.      */
  135.     function addParent(&$parent)
  136.     {
  137.         if (is_subclass_of($parent, 'XML_SVG_Element')) {
  138.             $parent->addChild($this);
  139.         }
  140.     }
  141.  
  142.     function copy()
  143.     {
  144.         if (version_compare(zend_version(), '2', '>')) {
  145.             return clone($this);
  146.         } else {
  147.             $xml_svg = $this;
  148.             return $xml_svg;
  149.         }
  150.     }
  151.  
  152.     /**
  153.      * Print each of the passed parameters, if they are set.
  154.      */
  155.     function printParams()
  156.     {
  157.         foreach (func_get_args() as $param) {
  158.             $_param = '_' . $param;
  159.             if (isset($this->$_param)) {
  160.                 switch ($param) {
  161.                 case 'filter':
  162.                     echo ' filter="url(#' . $this->$_param . ')"';
  163.                     break;
  164.  
  165.                 default:
  166.                     echo ' ' . str_replace('_', '-', $param) . '="' . $this->$_param . '"';
  167.                     break;
  168.                 }
  169.             }
  170.         }
  171.     }
  172.  
  173.     // Set any named attribute of an element to a value.
  174.     function setParam($param, $value)
  175.     {
  176.         $attr = '_' . $param;
  177.         $this->$attr = $value;
  178.     }
  179.  
  180.     // Get any named attribute of an element.
  181.     function getParam($param)
  182.     {
  183.         $attr = '_' . $param;
  184.         if (isset($this->$attr)) {
  185.             return $this->$attr;
  186.         } else {
  187.             return null;
  188.         }
  189.     }
  190.  
  191.     // Print out the object for debugging.
  192.     function debug()
  193.     {
  194.         echo '<pre>'; var_dump($this); echo '</pre>';
  195.     }
  196.  
  197. }
  198.  
  199. /**
  200.  * XML_SVG_Fragment
  201.  *
  202.  * @package XML_SVG
  203.  */
  204. class XML_SVG_Fragment extends XML_SVG_Element {
  205.  
  206.     var $_width;
  207.     var $_height;
  208.     var $_viewBox;
  209.     var $_x;
  210.     var $_y;
  211.  
  212.     function printElement()
  213.     {
  214.         echo '<svg';
  215.         $this->printParams('id', 'width', 'height', 'x', 'y', 'viewBox', 'style');
  216.         echo ' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' . "\n";
  217.         parent::printElement();
  218.         echo "</svg>\n";
  219.     }
  220.  
  221.     function bufferObject()
  222.     {
  223.         ob_start();
  224.         $this->printElement();
  225.         $output = ob_get_contents();
  226.         ob_end_clean();
  227.  
  228.         return $output;
  229.     }
  230. }
  231.  
  232. /**
  233.  * XML_SVG_Document
  234.  *
  235.  * This extends the XML_SVG_Fragment class. It wraps the XML_SVG_Frament output
  236.  * with a content header, xml definition and doctype.
  237.  *
  238.  * @package XML_SVG
  239.  */
  240. class XML_SVG_Document extends XML_SVG_Fragment {
  241.  
  242.     function printElement()
  243.     {
  244.         header('Content-Type: image/svg+xml');
  245.  
  246.         print('<?xml version="1.0" encoding="iso-8859-1"?>'."\n");
  247.         print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  248.             "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">' . "\n");
  249.  
  250.         parent::printElement();
  251.     }
  252.  
  253. }
  254.  
  255. /**
  256.  * XML_SVG_Group
  257.  *
  258.  * @package XML_SVG
  259.  */
  260. class XML_SVG_Group extends XML_SVG_Element {
  261.  
  262.     function printElement()
  263.     {
  264.         echo '<g';
  265.         $this->printParams('id', 'style', 'transform', 'filter');
  266.         print(">\n");
  267.         parent::printElement();
  268.         print("</g>\n");
  269.     }
  270.  
  271. }
  272.  
  273. /**
  274.  * XML_SVG_Textpath
  275.  *
  276.  * @package XML_SVG
  277.  */
  278. class XML_SVG_Textpath extends XML_SVG_Element {
  279.  
  280.     var $_text;
  281.     var $_x;
  282.     var $_y;
  283.     var $_dx;
  284.     var $_dy;
  285.     var $_rotate;
  286.     var $_textLength;
  287.     var $_lengthAdjust;
  288.  
  289.     function printElement($element = 'textpath')
  290.     {
  291.         echo '<' . $element;
  292.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  293.                            'textLength', 'lengthAdjust', 'style', 'transform');
  294.         echo '>' . htmlentities($this->_text);
  295.         parent::printElement();
  296.         echo "</$element>\n";
  297.     }
  298.  
  299.     function setShape($x, $y, $text)
  300.     {
  301.         $this->_x = $x;
  302.         $this->_y = $y;
  303.         $this->_text = $text;
  304.     }
  305.  
  306. }
  307.  
  308. /**
  309.  * XML_SVG_Text
  310.  *
  311.  * @package XML_SVG
  312.  */
  313. class XML_SVG_Text extends XML_SVG_Textpath {
  314.  
  315.     function printElement()
  316.     {
  317.         parent::printElement('text');
  318.     }
  319.  
  320.     function setShape($x, $y, $text)
  321.     {
  322.         $this->_x = $x;
  323.         $this->_y = $y;
  324.         $this->_text = $text;
  325.     }
  326.  
  327. }
  328.  
  329. /**
  330.  * XML_SVG_Tspan
  331.  *
  332.  * @package XML_SVG
  333.  */
  334. class XML_SVG_Tspan extends XML_SVG_Element {
  335.  
  336.     var $_text;
  337.     var $_x;
  338.     var $_y;
  339.     var $_dx;
  340.     var $_dy;
  341.     var $_rotate;
  342.     var $_textLength;
  343.     var $_lengthAdjust;
  344.  
  345.     function printElement()
  346.     {
  347.         echo '<tspan';
  348.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  349.                            'textLength', 'lengthAdjust', 'style', 'transform');
  350.         echo '>' . $this->_text;
  351.         if (is_array($this->_elements)) {
  352.             parent::printElement();
  353.         }
  354.         echo "</tspan>\n";
  355.     }
  356.  
  357.     function setShape($x, $y, $text)
  358.     {
  359.         $this->_x = $x;
  360.         $this->_y = $y;
  361.         $this->_text  = $text;
  362.     }
  363.  
  364. }
  365.  
  366. /**
  367.  * XML_SVG_Circle
  368.  *
  369.  * @package XML_SVG
  370.  */
  371. class XML_SVG_Circle extends XML_SVG_Element {
  372.  
  373.     var $_cx;
  374.     var $_cy;
  375.     var $_r;
  376.  
  377.     function printElement()
  378.     {
  379.         echo '<circle';
  380.  
  381.         $this->printParams('id', 'cx', 'cy', 'r', 'style', 'transform');
  382.         if (is_array($this->_elements)) {
  383.             // Print children, start and end tag.
  384.             echo ">\n";
  385.             parent::printElement();
  386.             echo "</circle>\n";
  387.         } else {
  388.             // Print short tag.
  389.             echo "/>\n";
  390.         }
  391.     }
  392.  
  393.     function setShape($cx, $cy, $r)
  394.     {
  395.         $this->_cx = $cx;
  396.         $this->_cy = $cy;
  397.         $this->_r  = $r;
  398.     }
  399.  
  400. }
  401.  
  402. /**
  403.  * XML_SVG_Line
  404.  *
  405.  * @package XML_SVG
  406.  */
  407. class XML_SVG_Line extends XML_SVG_Element {
  408.  
  409.     var $_x1;
  410.     var $_y1;
  411.     var $_x2;
  412.     var $_y2;
  413.  
  414.     function printElement()
  415.     {
  416.         echo '<line';
  417.         $this->printParams('id', 'x1', 'y1', 'x2', 'y2', 'style');
  418.         if (is_array($this->_elements)) {
  419.             // Print children, start and end tag.
  420.             print(">\n");
  421.             parent::printElement();
  422.             print("</line>\n");
  423.         } else {
  424.             // Print short tag.
  425.             print("/>\n");
  426.         }
  427.     }
  428.  
  429.     function setShape($x1, $y1, $x2, $y2)
  430.     {
  431.         $this->_x1 = $x1;
  432.         $this->_y1 = $y1;
  433.         $this->_x2  = $x2;
  434.         $this->_y2  = $y2;
  435.     }
  436.  
  437. }
  438.  
  439. /**
  440.  * XML_SVG_Rect
  441.  *
  442.  * @package XML_SVG
  443.  */
  444. class XML_SVG_Rect extends XML_SVG_Element {
  445.  
  446.     var $_x;
  447.     var $_y;
  448.     var $_width;
  449.     var $_height;
  450.     var $_rx;
  451.     var $_ry;
  452.  
  453.     function printElement()
  454.     {
  455.         echo '<rect';
  456.         $this->printParams('id', 'x', 'y', 'width', 'height',
  457.                            'rx', 'ry', 'style');
  458.         if (is_array($this->_elements)) {
  459.             // Print children, start and end tag.
  460.             print(">\n");
  461.             parent::printElement();
  462.             print("</rect>\n");
  463.         } else {
  464.             // Print short tag.
  465.             print("/>\n");
  466.         }
  467.     }
  468.  
  469.     function setShape($x, $y, $width, $height)
  470.     {
  471.         $this->_x = $x;
  472.         $this->_y = $y;
  473.         $this->_width  = $width;
  474.         $this->_height  = $height;
  475.     }
  476.  
  477. }
  478.  
  479. /**
  480.  * XML_SVG_Ellipse
  481.  *
  482.  * @package XML_SVG
  483.  */
  484. class XML_SVG_Ellipse extends XML_SVG_Element {
  485.  
  486.     var $_cx;
  487.     var $_cy;
  488.     var $_rx;
  489.     var $_ry;
  490.  
  491.     function printElement()
  492.     {
  493.         echo '<ellipse';
  494.         $this->printParams('id', 'cx', 'cy', 'rx', 'ry', 'style', 'transform');
  495.         if (is_array($this->_elements)) {
  496.             // Print children, start and end tag.
  497.             print(">\n");
  498.             parent::printElement();
  499.             print("</ellipse>\n");
  500.         } else {
  501.             // Print short tag.
  502.             print(" />\n");
  503.         }
  504.     }
  505.  
  506.     function setShape($cx, $cy, $rx, $ry)
  507.     {
  508.         $this->_cx = $cx;
  509.         $this->_cy = $cy;
  510.         $this->_rx  = $rx;
  511.         $this->_ry  = $ry;
  512.     }
  513.  
  514. }
  515.  
  516. /**
  517.  * XML_SVG_Polyline
  518.  *
  519.  * @package XML_SVG
  520.  */
  521. class XML_SVG_Polyline extends XML_SVG_Element {
  522.  
  523.     var $_points;
  524.  
  525.     function printElement()
  526.     {
  527.         echo '<polyline';
  528.         $this->printParams('id', 'points', 'style', 'transform');
  529.  
  530.         if (is_array($this->_elements)) {
  531.             // Print children, start and end tag.
  532.             print(">\n");
  533.             parent::printElement();
  534.             print("</polyline>\n");
  535.         } else {
  536.             // Print short tag.
  537.             print("/>\n");
  538.         }
  539.     }
  540.  
  541.     function setShape($points)
  542.     {
  543.         $this->_points = $points;
  544.     }
  545.  
  546. }
  547.  
  548. /**
  549.  * XML_SVG_Polygon
  550.  *
  551.  * @package XML_SVG
  552.  */
  553. class XML_SVG_Polygon extends XML_SVG_Element {
  554.  
  555.     var $_points;
  556.  
  557.     function printElement()
  558.     {
  559.         echo '<polygon';
  560.         $this->printParams('id', 'points', 'style', 'transform');
  561.         if (is_array($this->_elements)) {
  562.             // Print children, start and end tag.
  563.             print(">\n");
  564.             parent::printElement();
  565.             print("</polygon>\n");
  566.         } else {
  567.             // Print short tag.
  568.             print("/>\n");
  569.         }
  570.     }
  571.  
  572.     function setShape($points)
  573.     {
  574.         $this->_points = $points;
  575.     }
  576.  
  577. }
  578.  
  579. /**
  580.  * XML_SVG_Path
  581.  *
  582.  * @package XML_SVG
  583.  */
  584. class XML_SVG_Path extends XML_SVG_Element {
  585.  
  586.     var $_d;
  587.  
  588.     function printElement()
  589.     {
  590.         echo '<path';
  591.         $this->printParams('id', 'd', 'style', 'transform');
  592.         if (is_array($this->_elements)) {
  593.             // Print children, start and end tag.
  594.             print(">\n");
  595.             parent::printElement();
  596.             print("</path>\n");
  597.         } else {
  598.             // Print short tag.
  599.             print("/>\n");
  600.         }
  601.     }
  602.  
  603.     function setShape($d)
  604.     {
  605.         $this->_d = $d;
  606.     }
  607.  
  608. }
  609.  
  610. /**
  611.  * XML_SVG_Image
  612.  *
  613.  * @package XML_SVG
  614.  */
  615. class XML_SVG_Image extends XML_SVG_Element {
  616.  
  617.     var $_x;
  618.     var $_y;
  619.     var $_width;
  620.     var $_height;
  621.     var $_href;
  622.  
  623.     function printElement()
  624.     {
  625.         echo '<image';
  626.         $this->printParams('id', 'x', 'y', 'width', 'height', 'style');
  627.         if (!empty($this->_href)) {
  628.             echo ' xlink:href="' . $this->_href . '"';
  629.         }
  630.         if (is_array($this->_elements)) {
  631.             // Print children, start and end tag.
  632.             echo ">\n";
  633.             parent::printElement();
  634.             echo "</image>\n";
  635.         } else {
  636.             // Print short tag.
  637.             echo " />\n";
  638.         }
  639.     }
  640.  
  641.     function setShape($x, $y, $width, $height)
  642.     {
  643.         $this->_x = $x;
  644.         $this->_y = $y;
  645.         $this->_width  = $width;
  646.         $this->_height  = $height;
  647.     }
  648.  
  649. }
  650.  
  651. /**
  652.  * XML_SVG_Animate
  653.  *
  654.  * @package XML_SVG
  655.  */
  656. class XML_SVG_Animate extends XML_SVG_Element {
  657.  
  658.     var $_attributeName;
  659.     var $_attributeType;
  660.     var $_from;
  661.     var $_to;
  662.     var $_begin;
  663.     var $_dur;
  664.     var $_fill;
  665.  
  666.     function printElement()
  667.     {
  668.         echo '<animate';
  669.         $this->printParams('id', 'attributeName', 'attributeType', 'from', 'to',
  670.                            'begin', 'dur', 'fill');
  671.         if (is_array($this->_elements)) {
  672.             // Print children, start and end tag.
  673.             echo ">\n";
  674.             parent::printElement();
  675.             echo "</animate>\n";
  676.         } else {
  677.             echo " />\n";
  678.         }
  679.     }
  680.  
  681.     function setShape($attributeName, $attributeType = '', $from = '',
  682.                       $to = '', $begin = '', $dur = '', $fill = '')
  683.     {
  684.         $this->_attributeName = $attributeName;
  685.         $this->_attributeType = $attributeType;
  686.         $this->_from  = $from;
  687.         $this->_to = $to;
  688.         $this->_begin = $begin;
  689.         $this->_dur = $dur;
  690.         $this->_fill = $fill;
  691.     }
  692.  
  693. }
  694.  
  695. /**
  696.  * XML_SVG_Filter
  697.  *
  698.  * @package XML_SVG
  699.  */
  700. class XML_SVG_Filter extends XML_SVG_Element {
  701.  
  702.     function printElement()
  703.     {
  704.         echo '<filter';
  705.         $this->printParams('id');
  706.         if (is_array($this->_elements)) {
  707.             // Print children, start and end tag.
  708.             echo ">\n";
  709.             parent::printElement();
  710.             echo "</filter>\n";
  711.         } else {
  712.             echo " />\n";
  713.         }
  714.     }
  715.  
  716.     function addPrimitive($primitive, $params)
  717.     {
  718.         $this->addChild(new XML_SVG_FilterPrimitive($primitive, $params));
  719.     }
  720.  
  721. }
  722.  
  723. /**
  724.  * XML_SVG_FilterPrimitive
  725.  *
  726.  * @package XML_SVG
  727.  */
  728. class XML_SVG_FilterPrimitive extends XML_SVG_Element {
  729.  
  730.     var $_primitives = array('Blend',
  731.                              'ColorMatrix',
  732.                              'ComponentTransfer',
  733.                              'Composite',
  734.                              'ConvolveMatrix',
  735.                              'DiffuseLighting',
  736.                              'DisplacementMap',
  737.                              'Flood',
  738.                              'GaussianBlur',
  739.                              'Image',
  740.                              'Merge',
  741.                              'Morphology',
  742.                              'Offset',
  743.                              'SpecularLighting',
  744.                              'Tile',
  745.                              'Turbulence');
  746.  
  747.     var $_primitive;
  748.  
  749.     var $_in;
  750.     var $_in2;
  751.     var $_result;
  752.     var $_x;
  753.     var $_y;
  754.     var $_dx;
  755.     var $_dy;
  756.     var $_width;
  757.     var $_height;
  758.     var $_mode;
  759.     var $_type;
  760.     var $_values;
  761.     var $_operator;
  762.     var $_k1;
  763.     var $_k2;
  764.     var $_k3;
  765.     var $_k4;
  766.     var $_surfaceScale;
  767.     var $_diffuseConstant;
  768.     var $_kernelUnitLength;
  769.     var $_floor_color;
  770.     var $_flood_opacity;
  771.  
  772.     function XML_SVG_FilterPrimitive($primitive, $params = array())
  773.     {
  774.         parent::XML_SVG_Element($params);
  775.         $this->_primitive = $primitive;
  776.     }
  777.  
  778.     function printElement()
  779.     {
  780.         $name = 'fe' . $this->_primitive;
  781.         echo '<' . $name;
  782.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'width', 'height', 'in', 'in2',
  783.                            'result', 'mode', 'type', 'values', 'operator',
  784.                            'k1', 'k2', 'k3', 'k4', 'surfaceScale', 'stdDeviation',
  785.                            'diffuseConstant', 'kernelUnitLength',
  786.                            'flood_color', 'flood_opacity');
  787.         if (is_array($this->_elements)) {
  788.             // Print children, start and end tag.
  789.             echo ">\n";
  790.             parent::printElement();
  791.             echo '</' . $name . '>';
  792.         } else {
  793.             echo '/>';
  794.         }
  795.     }
  796.  
  797.     /**
  798.      * For feMerge elements.
  799.      */
  800.     function addMergeNode($in)
  801.     {
  802.         $this->addChild(new XML_SVG_FilterMergeNode(array('in' => $in)));
  803.     }
  804.  
  805. }
  806.  
  807. /**
  808.  * XML_SVG_FilterMergeNode
  809.  *
  810.  * @package XML_SVG
  811.  */
  812. class XML_SVG_FilterMergeNode extends XML_SVG_Element {
  813.  
  814.     var $_in;
  815.  
  816.     function printElement()
  817.     {
  818.         echo '<feMergeNode';
  819.         $this->printParams('in');
  820.         echo '/>';
  821.     }
  822.  
  823. }
  824.  
  825. /**
  826.  * XML_SVG_Use
  827.  *
  828.  * @package XML_SVG
  829.  */
  830. class XML_SVG_Use extends XML_SVG_Element {
  831.  
  832.     var $_symbol;
  833.  
  834.     function XML_SVG_Use($symbol, $params = array())
  835.     {
  836.         parent::XML_SVG_Element($params);
  837.         $this->_symbol = $symbol;
  838.     }
  839.  
  840.     function printElement()
  841.     {
  842.         echo '<use xlink:href="#' . $this->_symbol . '"/>';
  843.     }
  844.  
  845. }
  846.  
  847. /**
  848.  * XML_SVG_Defs
  849.  *
  850.  * @package XML_SVG
  851.  */
  852. class XML_SVG_Defs extends XML_SVG_Element {
  853.  
  854.     function printElement()
  855.     {
  856.         echo '<defs';
  857.         $this->printParams('id', 'style', 'transform');
  858.         echo ">\n";
  859.         parent::printElement();
  860.         echo "</defs>\n";
  861.     }
  862.  
  863. }
  864.  
  865. /**
  866.  * XML_SVG_Marker
  867.  *
  868.  * @package XML_SVG
  869.  */
  870. class XML_SVG_Marker extends XML_SVG_Element {
  871.  
  872.     var $_refX;
  873.     var $_refY;
  874.     var $_markerUnits;
  875.     var $_markerWidth;
  876.     var $_markerHeight;
  877.     var $_orient;
  878.  
  879.     function printElement()
  880.     {
  881.         echo '<marker';
  882.         $this->printParams('id', 'refX', 'refY', 'markerUnits',
  883.                            'markerWidth', 'markerHeight', 'orient');
  884.         if (is_array($this->_elements)) { // Print children, start and end tag.
  885.             print(">\n");
  886.             parent::printElement();
  887.             print("</marker>\n");
  888.         } else {
  889.             print("/>\n");
  890.         }
  891.     }
  892.  
  893.     function setShape($refX = '', $refY = '', $markerUnits = '',
  894.                       $markerWidth = '', $markerHeight = '', $orient = '')
  895.     {
  896.         $this->_refX = $refX;
  897.         $this->_refY  = $refY;
  898.         $this->_markerUnits = $markerUnits;
  899.         $this->_markerWidth = $markerWidth;
  900.         $this->_markerHeight = $markerHeight;
  901.         $this->_orient = $orient;
  902.     }
  903.  
  904. }
  905.  
  906. /**
  907.  * XML_SVG_Title
  908.  *
  909.  * @package XML_SVG
  910. */
  911. class XML_SVG_Title extends XML_SVG_Element {
  912.  
  913.     var $_title;
  914.  
  915.     function printElement()
  916.     {
  917.         echo '<title';
  918.         $this->printParams('id', 'style');
  919.         print(">\n");
  920.         print($this->_title);
  921.         parent::printElement();
  922.         print("</title>\n");
  923.     }
  924.  
  925. }
  926.  
  927. /**
  928.  * XML_SVG_Desc
  929.  *
  930.  * @package XML_SVG
  931.  */
  932. class XML_SVG_Desc extends XML_SVG_Element {
  933.  
  934.     var $_desc;
  935.  
  936.     function printElement()
  937.     {
  938.         echo '<desc';
  939.         $this->printParams('id', 'style');
  940.         echo '>' . $this->_desc;
  941.         parent::printElement();
  942.         echo "</desc>\n";
  943.     }
  944.  
  945. }
  946.  
  947. /**
  948.  * XML_SVG_Tref
  949.  *
  950.  * @package XML_SVG
  951.  */
  952. class XML_SVG_Tref extends XML_SVG_Element {
  953.  
  954.     var $_text;
  955.     var $_x;
  956.     var $_y;
  957.     var $_dx;
  958.     var $_dy;
  959.     var $_rotate;
  960.     var $_textLength;
  961.     var $_lengthAdjust;
  962.  
  963.     function printElement()
  964.     {
  965.         echo '<tref';
  966.         $this->printParams('id', 'x', 'y', 'dx', 'dy', 'rotate',
  967.                            'textLength', 'lengthAdjust', 'style');
  968.         echo '>' . $this->_text;
  969.         parent::printElement();
  970.         echo "</tref>\n";
  971.     }
  972.  
  973. }
  974.